/*
 * GPUC
 * 
 * Copyright © 2008 Attila T. Áfra <attila.afra@gmail.com>
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If
 * not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <GPUC/GPUC.h>

/*------------------------------------------------------------------------------------------------*/

namespace GPUC
{
    class Exception {};

    class NotInitializedException : public Exception {};
    class UnknownException : public Exception {};
    class InvalidOperationException : public Exception {};
    class InvalidArgumentException : public Exception {};
    class OutOfMemoryException : public Exception {};
    class CompileFailedException : public Exception {};
    class UnsupportedDeviceException : public Exception {};
    class UnsupportedStreamSizeException : public Exception {};
    class UnsupportedStreamTypeException : public Exception {};
    class UnsupportedStreamCountException : public Exception {};

    namespace Internal
    {
        void checkError();
        void checkError(GPUC_Error error);
        void throwException(GPUC_Error error);
    }
}

/*------------------------------------------------------------------------------------------------*/

void GPUC::Internal::throwException(GPUC_Error error)
{
    switch (error)
    {
    case GPUC_Error_NotInitialized:
        throw NotInitializedException();

    case GPUC_Error_Unknown:
        throw UnknownException();

    case GPUC_Error_InvalidOperation:
        throw InvalidOperationException();

    case GPUC_Error_InvalidArgument:
        throw InvalidArgumentException();

    case GPUC_Error_OutOfMemory:
        throw OutOfMemoryException();

    case GPUC_Error_CompileFailed:
        throw CompileFailedException();

    case GPUC_Error_UnsupportedDevice:
        throw UnsupportedDeviceException();

    case GPUC_Error_UnsupportedStreamSize:
        throw UnsupportedStreamSizeException();

    case GPUC_Error_UnsupportedStreamType:
        throw UnsupportedStreamTypeException();

    case GPUC_Error_UnsupportedStreamCount:
        throw UnsupportedStreamCountException();

    default:
        throw Exception();
    }
}

/*------------------------------------------------------------------------------------------------*/

void GPUC::Internal::checkError()
{
    const GPUC_Error error = GPUC_getError();

    if (error != GPUC_Error_None)
        throwException(error);
}

/*------------------------------------------------------------------------------------------------*/

void GPUC::Internal::checkError(GPUC_Error error)
{
    if (error != GPUC_Error_None)
        throwException(error);
}

/*------------------------------------------------------------------------------------------------*/
